package com.wangchao.administrator.zenmechi.ui.fragment.homefragment;

import android.content.Context;
import android.util.Log;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.wangchao.administrator.zenmechi.bean.homebean.GoodsHotListBean;
import com.wangchao.administrator.zenmechi.bean.homebean.Mainbean;
import com.wangchao.administrator.zenmechi.bean.homebean.NearbyMerchantListBean;
import com.wangchao.administrator.zenmechi.http.HttpHelper;
import com.wangchao.administrator.zenmechi.image.MyListView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2016/10/17.
 */
public class HomeModel implements HomeContract.Model {



    @Override
    public void getMainItem(Subscriber<Mainbean> subscriber, String stringtype, Map<String,String> urlMap) {
        HttpHelper.getInstance().getMaindata()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(subscriber);
    }

    @Override
    public List<ImageView> addlistvewimage(
                                List<GoodsHotListBean> goodsHotList, Context context) {
        List<ImageView> imageViewList=new ArrayList<>();
        for (int i=0;i<goodsHotList.size();i++){
            ImageView imageView=new ImageView(context);
            imageView.setLayoutParams(new ViewGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
            Glide.with(context).load(goodsHotList.get(i).getPrice()).into(imageView);
            imageViewList.add(imageView);

        }
       return imageViewList;
    }
    @Override
    public void setListViewAdapter(MyListView myListViewone,
                                   Context context, List<GoodsHotListBean> goodsHotList){
        Log.i("adapter","model");
        myListViewone.setAdapter(new ListAdapter(context,goodsHotList));
    }
    @Override
    public void setListViewAdaptertwo(
            MyListView myListViewtwo, Context context, List<NearbyMerchantListBean> nearbyMerchantList){
                myListViewtwo.setAdapter(new ListmarketAdapter(nearbyMerchantList,context));
    }

}
